package com.link.listener;

import com.link.condition.OperatingSystemCondition;
import com.link.notify.LinkEmailNotify;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

/**
 * 邮件通知配置类，只有在非window系统和Mac系统下才会生效，
 * 即只有在非window系统和非Mac系统下才会发送邮件通知
 * @author 郭闪
 * @date 2019/12/30
 */

@ConditionalOnProperty(prefix = "link.notify",
        name = "enable", havingValue = "true", matchIfMissing = false)

@Conditional(OperatingSystemCondition.class)
@Configuration
public class ListenerConfig {

    /**
     * 向框架中注入eureka事件监听bean
     * @author 郭闪
     * @date 2019/12/30
     * @param
     *
     */
    @Bean
    @DependsOn("linkEmailNotify")
    @ConditionalOnMissingBean(EurekaStateChangeListener.class)
    public EurekaStateChangeListener  eurekaStateChangeListener() {
        return new EurekaStateChangeListener();
    }

    /**
     * 想框架中注入邮件发送bean
     * @author 郭闪
     * @date 2019/12/30
     * @param
     *
     */
    @Bean
    @ConfigurationProperties(prefix = "link.notify.email")
    public LinkEmailNotify linkEmailNotify() {
        return new LinkEmailNotify();
    }
}
